package com.zjw.zy.componse.demo.fragment

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.Button
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.constraintlayout.compose.ConstraintLayout
import com.zjw.zy.componse.demo.base.BaseComposeFragment
import com.zjw.zy.componse.demo.ext.go
import com.zjw.zy.componse.demo.ui.theme.MyApplicationTheme

/**
 * @author     ：zhong.jw
 * @date       ：Created in 2023/2/16 10:21
 * @description：
 */
class WelComeFragment : BaseComposeFragment() {
    override fun onContentView(rootView: ComposeView) {
        rootView.setContent {
            MyApplicationTheme {
                Surface {
                    WelCome()
                }
            }
        }
    }

    override fun onSubscribeValue() {

    }


    @Composable
    fun Greeting(name: String, modifier: Modifier = Modifier) {
        Text(
            text = "$name!", modifier = modifier, fontSize = 20.sp, textAlign = TextAlign.Center
        )
    }


    @Composable
    fun WelcomeImage(modifier: Modifier) {
        Image(
            painter = painterResource(id = com.zjw.zy.componse.demo.R.drawable.icon_lover),
            contentDescription = null,
            modifier = modifier
                .wrapContentSize()
                .clip(CircleShape),
        )
    }

    @Composable
    @Preview
    fun WelCome() {
        ConstraintLayout(modifier = Modifier.padding(10.dp)) {
            val (p1, p2, p3) = remember {
                createRefs()
            }

            WelcomeImage(modifier = Modifier
                .fillMaxWidth()
                .constrainAs(p1) {
                    top.linkTo(parent.top)
                    start.linkTo(parent.start)
                    end.linkTo(parent.end)
                    bottom.linkTo(parent.bottom)
                })

            Spacer(modifier = Modifier.height(10.dp))

            Greeting(name = "这是使用ComposeUI开发的Demo", modifier = Modifier
                .fillMaxWidth()
                .constrainAs(p2) {
                    top.linkTo(p1.bottom)
                    start.linkTo(parent.start)
                    end.linkTo(parent.end)
                    bottom.linkTo(parent.bottom)
                })

            Spacer(modifier = Modifier.height(10.dp))

            Button(
                onClick = { go(com.zjw.zy.componse.demo.R.id.loginFragment) },
                modifier = Modifier.constrainAs(p3) {
                    bottom.linkTo(parent.bottom)
                    start.linkTo(parent.start)
                    end.linkTo(parent.end)
                }) {
                Text(text = "点击我开始体验")
            }
        }
    }

}


